<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="审批名称" prop="approveName">
        <el-input
          v-model="queryParams.approveName"
          placeholder="请输入审批名称"
          clearable
          style="width: 200px"
          @keyup.enter="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="dataList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="合同编号" align="center" prop="contractNo" />
      <el-table-column
        label="审批名称"
        align="center"
        prop="approveProcessName"
      />
      <el-table-column label="审批类型" align="center" prop="approveType" />
      <el-table-column label="状态" align="center" prop="isStatus">
        <template #default="scope">
          <el-tag type="info" v-if="scope.row.isStatus == 0">待审核</el-tag>
          <el-tag type="success" v-if="scope.row.isStatus == 1">已审核</el-tag>
          <el-tag type="error" v-if="scope.row.isStatus == 2">已驳回</el-tag>
          <el-tag type="error" v-if="scope.row.isStatus == 3">已撤消</el-tag>
        </template>
      </el-table-column>
      <!-- <el-table-column
        label="下一审批节点"
        align="center"
        prop="approveProcessStepName"
      /> -->
      <el-table-column label="添加时间" align="center" prop="addTime" />

      <el-table-column
        label="操作"
        width="180"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            link
            type="primary"
            @click="handleDetail(scope.row)"
            v-hasPermi="['system:process:query']"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script setup name="already">
import {
  addTransactionType,
  editTransactionType,
  delTransactionType,
} from "@/api/optionsSystem/divide";
import { listSending, delSending } from "@/api/task/sending";
const { proxy } = getCurrentInstance();
const router = useRouter();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
const dataList = ref([]);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    approveName: undefined,
    isStatus: 1,
  },
  rules: {
    approveName: [
      { required: true, message: "审批名称不能为空", trigger: "blur" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);

/** 查询岗位列表 */
function getList() {
  loading.value = true;
  listSending(queryParams.value).then((response) => {
    dataList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}
/**详情 */
function handleDetail(row) {
  const { operationId, id, approveType } = row;
  router.push({
    path: "sendDetail",
    query: {
      id,
      operationId,
      approveType,
    },
  });
}
/**取消申请 */
function handleCencel() {}

/** 表单重置 */
function reset() {
  form.value = {};
  proxy.resetForm("postRef");
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}

/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.postId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 删除按钮操作 */
function handleDelete(row) {
  const id = row.id || ids.value;
  proxy.$modal
    .confirm("是否确认取消申请？")
    .then(function () {
      return delSending(id);
    })
    .then(() => {
      getList();
      proxy.$modal.msgSuccess("操作成功");
    })
    .catch(() => {});
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "system/post/export",
    {
      ...queryParams.value,
    },
    `post_${new Date().getTime()}.xlsx`
  );
}

getList();
</script>
